package StudentDemo;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public class Main {
    public static void main(String[] args) {
        List<Student> list = new ArrayList<>();
        Student s1 = new Student("001","小红",18);
        Student s2 = new Student("004","小明",14);
        Student s3 = new Student("002","小刚",14);
        Student s4 = new Student("006","小勇",17);
        //添加学生信息
        list.add(s1);
        list.add(s2);
        list.add(s3);
        list.add(s4);

        //插入数据
        Student s5 = new Student("003","小亮",20);
        list.add(1,s5);

        //遍历
        //增强for
        for (Student s:list){
            System.out.println(s);
        }

        //Iterator
        Iterator<Student> it = list.iterator();
        while (it.hasNext()){
            System.out.println(it.next());
        }

    }
}
